package com.topera.commonutils.serializableTest;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

/**
 * 序列化反序列化测试
 */
public class Student  implements Serializable {

    private Integer age;
    private String name;

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 测试
     * @param args
     */
    public static void main(String[] args) {

        //序列化测试
        /*try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\text.out"));
            Student student = new Student();
            student.setAge(25);
            student.setName("浦振江");
            oos.writeObject(student);
            oos.flush();
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }*/

        //反序列化测试
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\text.out"));
            Student student = (Student)ois.readObject();
            System.out.println("name:"+student.getName());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }



}
